const Queue = require("promise-queue");


let queue = new Queue(1, Infinity);

let w3 = function () {
    return new Promise(r => {
        setTimeout($ => {
            console.log("3s...");
            r();
        }, 3000)
    });
};
let w2 = function () {
    return new Promise(r => {
        setTimeout($ => {
            console.log("2s...");
            r();
        }, 2000)
    });
};
let count_aw1 = 0;
let w1 = function () {
    return new Promise(r => {
        setTimeout($ => {
            console.log("1s...");
            console.log({ count_aw1 });
            if (count_aw1 < 10) {
                count_aw1++;
                queue.add(w1);
            }

            r();
        }, 1000)
    });
};

queue.add(w3);
queue.add(w3);
queue.add(w2);
queue.add(w1);